<extend name="./public/frame.html"/>

<style>
    .layui-layer-loading .layui-layer-content {

        background-position: center;
        width: 100%;

    }
    .layui-layer-loading .layui-layer-content p{    text-align: center;
        color: #fff;
        vertical-align: bottom;
        height: 40%;
        line-height: 100%;
        position: absolute;
        left: 0px;
        bottom: 0px;
        width: 100%;}
</style>

<block name="content">
    <div class="layui-row">
        <div class="layui-col-xs6">
            <div class="layui-inline" style="margin-right: 10px">
                <input type="text" class="layui-input date" readonly id="start" placeholder="提现申请时间">
            </div>到
            <div class="layui-inline">
                <input type="text" class="layui-input date" readonly id="end" placeholder="提现申请时间">
            </div>
        </div>

        <div class="layui-col-xs6 layui-col-md4 layui-col-lg3">
            <div class="layui-btn-group">
                <button class="layui-btn" data-type="search">搜索</button>
                <button class="layui-btn layui-btn-disabled" data-type="" id="reset">复位</button>
                <a href="javascript:void(0)" class="lea_but" id="withdraw_batch"><button class="layui-btn" style="background-color: #5FB878" data-type="withdraw_batch">批量支付</button></a>
            </div>

        </div>
    </div>

    <table class="layui-table"
           lay-data="{cellMinWidth: 80, height:'auto', url:'{$url}', id:'cash'}"
           lay-filter="cash">
        <thead>
        <tr>
            <th lay-data="{field:'wait_num_total', width:200,}">待提现总笔数</th>
            <th lay-data="{field:'wait_money_total', width:200,}">待提现总钱数(元)</th>
        </tr>
        </thead>
    </table>

    <script type="application/javascript">
        layui.use(['table', 'laydate', 'form', 'element'], function () {
            var table = layui.table
                , form = layui.form
                , element = layui.element
                , laydate = layui.laydate;
            lay('.date').each(function () {
                laydate.render({elem: this, type: 'date', trigger: 'click'});
            });


            //点击查看 批量支付信息
            $(document).on('click', '#withdraw_batch', function(){
                var start_time = $('#start').val();
                var end_time = $('#end').val();

////                timer = setTimeout(query(), 6000);
//
//                function query(){
//                    //同步请求
//                    $.ajax({
//                        type: "post",
//                        url: "/admin/FrWithdraw/lookPro",
//                        cache:false,
//                        async:false,
//                        dataType: "json",
//                        success: function(r){
//                            switch (r['code']) {
//                                case 1 :
//                                var mengceng = layer.open({
//                                    type: 3,
//                                    title: '',
//                                    shadeClose: false,
//                                    shade: 0.8,
//                                    area: ['100%', '100%'],
//                                    closeBtn: 0,
//                                    content:'<div class="layui-progress layui-progress-big" lay-showPercent="yes">\n' +
//                                                '<div class="layui-progress-bar layui-bg-green" lay-percent="' + r['pro'] + '"></div>\n' +
//                                             '</div>'
//                                });
//
//                                if(r['code'] === '100.00') {
//                                    layui.close(mengceng);
//                                }
//
//                                break;
//                                case 2:
//                                    break;
//
//                            }
//                        }
//                    });
//
//
//                }
//
////                clearTimeout(timer);


                layer.confirm('确认提现？！', function (index) {

                    var mengceng = layer.open({
                        type: 3,
                        title: '',
                        shadeClose: false,
                        shade: 0.8,
                        area: ['100%', '100%'],
                        closeBtn: 0,
                        content:'<p>正在批量支付中...请勿关闭页面</p>'
                    });

                    $.post('/admin/driver_withdraw/withdrawBatch', {'start': start_time, 'end': end_time}, function (res) {
                        switch (res['code']) {
                            case 1:
                                layer.close(mengceng);
                                var pay_result = layer.open({
                                    type: 2,
                                    title: '批量支付结果',
                                    shadeClose: false,
                                    shade: 0.8,
                                    area: ['800px', '40%'],
                                    content: '{:url("/admin/driver_withdraw/withdrawBatchRes", "already_pay_money=")}' + res['data']['already_pay_money'] + "&withdraw_success_num=" + res['data']['withdraw_success_num'] + "&fail_pay_money=" + res['data']['fail_pay_money']  + "&withdraw_fail_num=" +  res['data']['withdraw_fail_num'] + "&abnormal_pay_money=" + res['data']['abnormal_pay_money'] + "&withdraw_abnormal_num=" + res['data']['withdraw_abnormal_num'],
                                    end: function(){
                                        window.location.reload();
                                    }
                                });
                                break;
                            case 2:
                                layer.close(mengceng);
                                layer.msg(res['msg'], {icon: 5,time:2000}, function(){
                                window.location.reload();
                                });
                                break;
                            default:
                                layer.msg(res['msg'], {icon: 5});
                                break;
                        }
                    }, 'json');
                    layer.close(index);
                });

         })

            var active = {
                search: function () {
                    var start = $('#start').val();
                    var end = $('#end').val();
                    var reset = $('#reset');
                    if (start || end) {
                        reset.removeClass('layui-btn-disabled').addClass('layui-btn-normal').data('type', 'reset');
                        table.reload('cash', {
                            url: '/admin/driver_withdraw/withdrawBatchInfo?action=search',
                            where: {
                                start: start,
                                end: end
                            }
                        });
                    } else {
                        reset.removeClass('layui-btn-normal').addClass('layui-btn-disabled').data('type', '');
                        alert('搜索项不能为空');
                    }
                }
                , reset: function () {
                    var reset = $('#reset');
                    if (reset.data('type') !== '') {
                        table.reload('cash', {
                            url: '/admin/driver_withdraw/withdrawBatchInfo', where: {}
                        });
                    }
                    $('.layui-input').each(function () {
                        $(this).val('');
                    });
                    $('.layui-this').each(function () {
                        $(this).removeClass('layui-this');
                    });
                    reset.removeClass('layui-btn-normal').addClass('layui-btn-disabled').data('type', '');
                }
            };

            $('.layui-btn').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
        });

    </script>
</block>
